﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Me.Prettyprint.Cassandra.Utils;

namespace Me.Prettyprint.Cassandra.Connection
{
    /// <summary>
    /// Validation of DataCenter is simple. The validator is instantiated with a list
    /// of data centers. Validate will check if the datacenter is in the list. If there
    /// isn't any datacenter defined, it returns true.
    /// </summary>
    public class DataCenterValidator
    {
        private Logger logger = new Logger(typeof(DataCenterValidator));
        private Dictionary<string,string> datacenters;

        public DataCenterValidator(List<string> dataCenters)
        {
            if (dataCenters != null)
            {
                this.datacenters = new Dictionary<string, string>();
                foreach(string dc in dataCenters)
                {
                    this.datacenters.Add(dc, dc);
                }
            }
        }
        public bool Validate(string dcName)
        {
            // If the DC is not defined (i.e: single cluster) always returns TRUE
            if (datacenters == null || dcName == null)
            {
                return true;
            }
            else
            {
                return datacenters.ContainsKey(dcName);
            }
        }
    }
}
